﻿package net.wangit.dev.chart;

import net.wangit.Unit;
import net.wangit.context.ActionContext;
import net.wangit.dev.ConsoleDomainUtil;
import net.wangit.support.UnitInterceptor;
import net.wangit.util.Checker;

public class ChartPreviewUI implements UnitInterceptor {

	public ChartPreviewUI() {
	}

	public String intercept(ActionContext ac, Unit unit) throws Exception {
		String domain = ConsoleDomainUtil.getDomain(ac);
		String chartId = ac.getRequestParameter("chartid");
		if (!Checker.isEmpty(domain) && !Checker.isEmpty(chartId))
			unit.getElement("preview").setLink(
					(new StringBuilder("/chart?domain=")).append(domain)
							.append("&chartid=").append(chartId).toString());
		return unit.write(ac);
	}
}
